﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Caching;

namespace DynamicQuartz.Common
{
    public class ServiceCacheHelper
    {
        private static readonly ObjectCache Cache = MemoryCache.Default;
        private static readonly CacheItemPolicy CacheItemPolicy = new CacheItemPolicy();

        public static T Get<T>(string key)
        {
            return (T)Cache[key];
        }

        public static void Set<T>(string key, T value, TimeSpan expirationTime)
        {
            CacheItemPolicy.AbsoluteExpiration = DateTimeOffset.Now.Add(expirationTime);
            Cache.Add(new CacheItem(key, value), CacheItemPolicy);
        }

        public static bool Contains(string key)
        {
            return Cache.Contains(key);
        }

        public static void Remove(string key)
        {
            Cache.Remove(key);
        }
    }
}
